using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Reflection;

namespace LonCanvas
{
    abstract class DrawObjectBase
    {
        float m_width;
        Color m_color;
        DrawingLayer m_layer;

        enum eFlags
        {
            selected = 0x00000001,
            highlighted = 0x00000002,
            useLayerWidth = 0x00000004,
            useLayerColor = 0x00000008,
        }
        int m_flag = (int)(eFlags.useLayerWidth | eFlags.useLayerColor);
        bool GetFlag(eFlags flag)
        {
            return ((int)m_flag & (int)flag) > 0;
        }
        void SetFlag(eFlags flag, bool enable)
        {
            if (enable)
                m_flag |= (int)flag;
            else
                m_flag &= ~(int)flag;
        }

      
        public bool UseLayerWidth
        {
            get { return GetFlag(eFlags.useLayerWidth); }
            set { SetFlag(eFlags.useLayerWidth, value); }
        }
     
        public bool UseLayerColor
        {
            get { return GetFlag(eFlags.useLayerColor); }
            set { SetFlag(eFlags.useLayerColor, value); }
        }
      
        public float Width
        {
            set { m_width = value; }
            get
            {
                if (Layer != null && UseLayerWidth)
                    return Layer.Width;
                return m_width;
            }
        }
      
        public Color Color
        {
            set { m_color = value; }
            get
            {
                if (Layer != null && UseLayerColor)
                    return Layer.Color;
                return m_color;
            }
        }
        public DrawingLayer Layer
        {
            get { return m_layer; }
            set { m_layer = value; }
        }

        abstract public void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap);
        public virtual bool Selected
        {
            get { return GetFlag(eFlags.selected); }
            set { SetFlag(eFlags.selected, value); }
        }
        public virtual bool Highlighted
        {
            get { return GetFlag(eFlags.highlighted); }
            set { SetFlag(eFlags.highlighted, value); }
        }

        public virtual void Copy(DrawObjectBase acopy)
        {
            UseLayerColor = acopy.UseLayerColor;
            UseLayerWidth = acopy.UseLayerWidth;
            Width = acopy.Width;
            Color = acopy.Color;
        }

    }
}
